import requests
import re
from decimal import Decimal



def get_gongji(zizhi,liliang,chengzhang,level):
    base_url = 'http://calculator.webapp.163.com/xyq_mnjd_gj/mnjdgjs?callback=jQuery1640018944610373485604_1632617639659&zz={}&gj0={}&czl={}&lv={}&_=1632619393826'
    full_url = base_url.format(zizhi, liliang, chengzhang, level)
    html = requests.get(full_url)
    s = re.findall("\d+", html.text)[0]
    return s

def ji_suan_gong_ji(zizhi,liliang,chengzhang,level):
    gongji = (Decimal(chengzhang) * Decimal(liliang) / Decimal(1000)) + (Decimal(zizhi) * Decimal(level) *(Decimal(14)+Decimal(10)*(Decimal(chengzhang)/Decimal(1000)))  )/ Decimal(7500)
    return gongji

def get_xue(zizhi,tili,chengzhang,level):
    base_url = 'http://calculator.webapp.163.com/xyq_mnjd_hp/mnjdhps?callback=jQuery164009946268189223173_1632819800348&zz={}&hp0={}&czl={}&lv={}&_=1632819811898'
    full_url = base_url.format(zizhi, tili, chengzhang, level)
    html = requests.get(full_url)
    s = re.findall("\d+", html.text)[0]
    return s

def zisuan_xue(zizhi,tili,chengzhang,level):
    #Decimal(level)*Decimal(zizhi)/Decimal(1000)+Decimal(chengzhang)*Decimal(tili)*Decimal(6)/Decimal(1000)
    return Decimal(level)*Decimal(zizhi)/Decimal(1000)+Decimal(chengzhang)*Decimal(tili)*Decimal(6)/Decimal(1000)



def get_fang(zizhi,naili,chengzhang,level):
    base_url = 'http://calculator.webapp.163.com/xyq_mnjd_fy/mnjdfys?callback=jQuery164009946268189223173_1632819800351&zz={}&fy0={}&czl={}&lv={}&_=1632819811900'
    full_url = base_url.format(zizhi, naili, chengzhang, level)
    html = requests.get(full_url)
    s = re.findall("\d+", html.text)[0]
    return s

def zisuan_fang(zizhi,dianshu,chengzhang,level):
    return Decimal(level)*Decimal(zizhi)*(Decimal(10)+Decimal(20)/Decimal(3)*Decimal(chengzhang))/Decimal(7500)+Decimal(chengzhang)*Decimal(dianshu)*Decimal(1.25)



def get_ling(ti, mo,nai,li,zz, level):
    base_url = 'http://calculator.webapp.163.com/xyq_mnjd_ll/mnjdlls?callback=jQuery164009946268189223173_1632819800352&hp0={}&mp0={}&fy0={}&gj0={}&hpzz={}&lv={}&_=1632819811901'
    full_url = base_url.format(ti, mo,nai,li,zz, level)
    html = requests.get(full_url)
    s = re.findall("\d+", html.text)[0]
    return s

def zisuan_ling(ti, mo,nai,li,zz, level):
    return level*(zz/1000+4)/5+mo*0.7+li*0.4+ti*0.3+nai*0.2
    #return 1


def get_lan(zizhi,dianshu,chengzhang,level):
    base_url = 'http://calculator.webapp.163.com/xyq_mnjd_mp/mnjdmps?callback=jQuery164009946268189223173_1632819800349&zz={}&mp0={}&czl={}&lv={}&_=1632819811899'
    full_url = base_url.format(zizhi, dianshu, chengzhang, level)
    html = requests.get(full_url)
    s = re.findall("\d+", html.text)[0]
    return s

def zisuan_lan(zizhi,dianshu,chengzhang,level):
    return level*zizhi/500+dianshu*chengzhang*3


if __name__ == '__main__':
    # for zizhi in range(1000, 1600, 100):125 1048
    #     for liliang in range(100, 700, 100):
    #         for chengzhang in range(1200, 1270, 10):
    #             for level in range(0, 109, 20):
    #                 gong_ji=get_gongji(zizhi, liliang, chengzhang, level)
    #                 zisuan=ji_suan_gong_ji(zizhi, liliang, chengzhang, level)
    #                 if zisuan-int(gong_ji)>3:
    #                     print('自算: {} === 官方 : {} =====差值: {}'.format(zisuan.__str__(), gong_ji,
    #                                                                   (zisuan - int(gong_ji)).__str__()))

    gong_ji=get_gongji(1345,609,1220,113)
    zisuan=ji_suan_gong_ji(1345,609,1220,113)
    print('攻击 自算: {} === 官方 : {} =====差值: {}'.format(zisuan.__str__(), gong_ji,(zisuan - int(gong_ji)).__str__()))

    xue=get_xue(4124,212,1220,113)
    zisuan_xue=zisuan_xue(4124,212,1220,113)
    print('血 自算: {} === 官方 : {} =====差值: {}'.format(zisuan_xue.__str__(), xue,(zisuan_xue - int(xue)).__str__()))

    fang=get_fang(1166,136,1220,113)
    zi_fang=zisuan_fang(1166,136,1.22,113)
    print('防御 自算: {} === 官方 : {} =====差值: {}'.format(zi_fang.__str__(), fang,(zi_fang - int(fang)).__str__()))

    ling_li_guan=get_ling(212,124,136,609,2596,113)
    ling_li_zi=zisuan_ling(212,124,136,609,2596,113)
    print('灵力 自算: {} === 官方 : {} =====差值: {}'.format(ling_li_zi.__str__(), ling_li_guan,(ling_li_zi - int(ling_li_guan)).__str__()))

    lan_guan=get_lan(2596,124,1220,113)
    lan_zi=zisuan_lan(2596,124,1.22,113)
    print('蓝 自算: {} === 官方 : {} =====差值: {}'.format(lan_zi.__str__(), lan_guan,(lan_zi - int(lan_guan)).__str__()))